Top 10 Events#

Setup#

First, we need to import all the necessary libraries. Some of them are specifically developed to handle the download and plotting of the data and are hosted at the indicators set-up repository in GitHub

Hide code cell source
import warnings
warnings.filterwarnings("ignore")

import os
import os.path as op
import sys
import folium

import numpy as np
import pandas as pd

sys.path.append("../../../../indicators_setup")
from ind_setup.plotting_int import plot_timeseries_interactive
from ind_setup.colors import get_df_col
from ind_setup.tables import plot_df_table, get_data_metrics, table_temperature_summary

sys.path.append("../../../functions")
from data_downloaders import GHCN

Define location and variables of interest#

country = 'Palau'
vars_interest = ['TMIN', 'TMAX']

Observations from Koror Station#

The data used for this analysis comes from the GHCN (Global Historical Climatology Network)-Daily database.
This a database that addresses the critical need for historical daily temperature, precipitation, and snow records over global land areas. GHCN-Daily is a composite of climate records from numerous sources that were merged and then subjected to a suite of quality assurance reviews. The archive includes over 40 meteorological elements including temperature daily maximum/minimum, temperature at observation time, precipitation and more.

https://www.ncei.noaa.gov/data/global-historical-climatology-network-daily/doc/GHCND_documentation.pdf

update_data = False
path_data = "../../../data"
path_figs = "../../../matrix_cc/figures" 
Hide code cell source
if update_data:
    df_country = GHCN.get_country_code(country)
    print(f'The GHCN code for {country} is {df_country["Code"].values[0]}')

    df_stations = GHCN.download_stations_info()
    df_country_stations = df_stations[df_stations['ID'].str.startswith(df_country.Code.values[0])]
    print(f'There are {df_country_stations.shape[0]} stations in {country}')
Hide code cell source
if update_data:
    GHCND_dir = 'https://www.ncei.noaa.gov/data/global-historical-climatology-network-daily/access/'
    id = 'PSW00040309' # Koror Station
    dict_min = GHCN.extract_dict_data_var(GHCND_dir, 'TMIN', df_country_stations.loc[df_country_stations['ID'] == id])[0][0]
    dict_max = GHCN.extract_dict_data_var(GHCND_dir, 'TMAX', df_country_stations.loc[df_country_stations['ID'] == id])[0][0]
    st_data = pd.concat([dict_min['data'], (dict_max['data'])], axis=1).dropna()
    st_data['diff'] = st_data['TMAX'] - st_data['TMIN']
    st_data['TMEAN'] = (st_data['TMAX'] + st_data['TMIN'])/2
    st_data.to_pickle(op.join(path_data, 'GHCN_surface_temperature.pkl'))
else:
    st_data = pd.read_pickle(op.join(path_data, 'GHCN_surface_temperature.pkl'))
df = table_temperature_summary(st_data)
fig = plot_df_table(df.T, figsize = (500, 340),)
../../../_images/7ba2bb71b306790603b38d62937f90338c95b25134072785bf35549f2c31b7ec.png

Monthly#

st_data = st_data.resample('M').mean()
nevents = 10
top_10 = st_data.sort_values(by='TMAX', ascending=False).head(nevents)
dict_plot = [{'data' : st_data, 'var' : 'TMAX', 'ax' : 1, 'label' : 'TMAX'}]
scatter_dict = [{'data' : top_10, 'var' : 'TMAX', 'ax' : 1, 'label' : 'Top 10 Events'}]

fig = plot_timeseries_interactive(dict_plot, trendline=True, scatter_dict = scatter_dict, figsize = (25, 12))

Generate table#

Table sumarizing different metrics of the data analyzed in the plots above

fig = plot_df_table(np.round(top_10, 2)[['TMAX']])
../../../_images/107a1fe7b28147ce978c1744b57c3b4a74a507b11cafb57ca588942cde27ea5f.png

Annual#

st_data = st_data.resample('Y').mean()
top_10 = st_data.sort_values(by='TMAX', ascending=False).head(10)
dict_plot = [{'data' : st_data, 'var' : 'TMAX', 'ax' : 1, 'label' : 'TMAX'}]
scatter_dict = [{'data' : top_10, 'var' : 'TMAX', 'ax' : 1, 'label' : 'Top 10 Events'}]
fig = plot_timeseries_interactive(dict_plot, trendline=True, scatter_dict = scatter_dict, figsize = (25, 12));

Generate table#

Table sumarizing different metrics of the data analyzed in the plots above

fig = plot_df_table(np.round(top_10, 2)[['TMAX']])
../../../_images/be773ae9b896417a945a65f46ba93cd3ff1357fabe3f43df95e4e974d3f88914.png